package net.easyjava.test.aliyun.oss;

import net.easyjava.third.aliyun.oss.AliyunOSSClient;
import net.easyjava.tools.qrcode.zxing.ZxingTools;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
 * Created by wxnacy on 16/6/29.
 */
public class AliyunOSSClientEJ {
    static String KEY_ID = "9I1VpgURzvT6t7Zb";
    static String KEY_SECRET = "JVXlHhYcZbFJ0cqLxJs9ySLo0IZuak";

    static String END_POINT = "oss-cn-beijing.aliyuncs.com";

    static String CDN_BUCKET = "cdn-easyjava-net";
    static String CDN_HTTP = "http://cdn.easyjava.net/";

    static AliyunOSSClient client;
    static {
        client = AliyunOSSClient.getInstance(KEY_ID,KEY_SECRET);
    }

    public static void main(String[] args) {
//        uploadUrl();

        String uploadId = client.getMultipartUploadId(END_POINT,CDN_BUCKET,"test/multi/www.mp3");
        System.out.println("uploadId = " + uploadId);
    }

    public static void uploadUrl(){
        try {
            String key = client.upload("http://"+END_POINT,CDN_BUCKET,
                    new URL("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css"),
                    "libs/font-awesome/4.4.0/css/font-awesome.min.css");
            System.out.printf("%s%s", CDN_HTTP, key);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void uploadPath(){
        try {
            String key = client.upload(END_POINT,CDN_BUCKET,
                    new File("http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.map"),
                    "libs/jquery/2.1.4/jquery.min.map");
            System.out.printf("%s%s", CDN_HTTP, key);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
